#include "MainMenuLayer.h"
#include "Helper.h"
#include "SceneFactory.h"

enum MAINMENU_ITEM
{
    MAINMENU_ITEM_LEFT,
    MAINMENU_ITEM_RIGHT,
    MAINMENU_ITEM_OPTION_MIN,
    MAINMENU_ITEM_START,
    MAINMENU_ITEM_OPTION_MAX
};

bool MainMenuLayer::init()
{
	Layer::init();
	auto background = Sprite::create("mainmenu_img_bkg.png");
	background->setPosition(Vec2(400, 240));
	addChild(background);
	auto title = Sprite::create("mainmenu_img_title.png");
	title->setPosition(Vec2(400, 280));
	addChild(title);
	auto callback = CC_CALLBACK_1(MainMenuLayer::menuCallback, this);
	auto itemArrowLeft = Helper::createButton("mainmenu_btn_left.png", callback);
	itemArrowLeft->setPosition(Vec2(260, 40));
	itemArrowLeft->setTag(MAINMENU_ITEM_LEFT);
	auto itemArrowRight = Helper::createButton("mainmenu_btn_right.png", callback);
	itemArrowRight->setPosition(Vec2(540, 40));
	itemArrowRight->setTag(MAINMENU_ITEM_RIGHT);
	auto itemOption = Helper::createButton("mainmenu_btn_start.png", callback);
	itemOption->setPosition(Vec2(400, 40));
	itemOption->setTag(MAINMENU_ITEM_START);
	auto menu = Menu::create(itemArrowLeft, itemArrowRight, itemOption, nullptr);
	menu->setPosition(Vec2::ZERO);
	addChild(menu);
	return true;
}

void MainMenuLayer::menuCallback(Ref* sender)
{
	switch (((MenuItem *) sender)->getTag()) {
	case MAINMENU_ITEM_LEFT:
		break;
	case MAINMENU_ITEM_RIGHT:
		break;
	case MAINMENU_ITEM_START:
        replaceGameScene();
		break;
	}
}

void MainMenuLayer::replaceGameScene()
{
    Director::getInstance()->replaceScene(SceneFactory::createGame());
}
